package com.os;

import java.io.IOException;
import java.io.InputStream;

/**
 * ${DESCRIPTION}
 *
 * @author xhc
 * @date 2018-10-12 9:20
 */
public class CommUtil {

    public static final int Word=0;
    public static final int Excel=1;
    public static final int Pdf=2;
    /**
     * 读取license文件
     * @param iType
     * @return
     */
    public static boolean getLicense(int iType) {
        boolean result = false;
        InputStream license =null;
        try {
            license =CommUtil.class.getClassLoader().getResourceAsStream("license.xml");

            if(license!=null) {
                if(iType==Word) {
                    com.aspose.words.License aposeLic = new com.aspose.words.License();
                    aposeLic.setLicense(license);
                }else if(iType==Excel){
                    com.aspose.cells.License aposeLic = new com.aspose.cells.License();
                    aposeLic.setLicense(license);
                }else if(iType==Pdf){
                    //com.aspose.pdf.License aposeLic = new com.aspose.pdf.License();
                    //aposeLic.setLicense(license);
                }
                result = true;
            }else{
                System.out.println("授权文件未找到！");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                if(license!=null){
                    license.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return result;
    }
}
